/*
 * @Description: 电影剧集控制层
 * @Author: fhw
 * @Date: 2024-06-15
 */

import { Controller, Get, Post, Body, Query, HttpCode, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiResponse, ApiOperation, ApiBody, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { IdDto } from 'src/common/dto/dto';
import { MoviesEpisodeEntity } from './entities/movies-episode.entity';
import { MoviesEpisodeService } from './movies-episode.service';
import { LogOperation } from '../operation-record/log.decorator';
import { OperateType, OperationRecordType } from '../operation-record/entities/operation-record.entity';
import { CreateMoviesEpisodeDto, GetMoviesEpisodeDto, UpdateMoviesEpisodeDto } from './dto/movies-episode.dto';

@ApiBearerAuth() // Swagger文档设置Token
@ApiTags('电影剧集管理')
@Controller('admin/movies-episode')
export class MoviesEpisodeController {
  constructor(private readonly episodeService: MoviesEpisodeService) { }

  /** 获取电影剧集列表 */
  @HttpCode(200)
  @Get('/getEpisodePage')
  @ApiResponse({
    status: 200,
    description: '电影剧集列表',
    type: MoviesEpisodeEntity,
    isArray: true,
  })
  @ApiOperation({
    tags: ['获取电影剧集'],
    summary: '获取电影剧集列表',
    operationId: 'getEpisodePage',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async getEpisodePage(@Query() params: GetMoviesEpisodeDto) {
    return this.episodeService.getEpisodePage(params);
  }

  /** 创建电影剧集 */
  @HttpCode(200)
  @Post('/createEpisode')
  @ApiBody({
    description: '创建电影剧集',
    type: CreateMoviesEpisodeDto,
  })
  @ApiOperation({
    summary: '创建电影剧集',
    operationId: 'createEpisode',
  })
  @LogOperation({
    operateType: OperateType.add,
    operation: `创建电影剧集`,
    name: '创建',
    outside: OperationRecordType.moviesEpisode,
    entity: MoviesEpisodeEntity,
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async createEpisode(@Body() body: CreateMoviesEpisodeDto) {
    return this.episodeService.createEpisode(body);
  }

  /** 更新电影剧集 */
  @HttpCode(200)
  @Post('/updateEpisode')
  @ApiBody({
    description: '更新电影剧集信息',
    type: UpdateMoviesEpisodeDto,
  })
  @ApiOperation({
    summary: '更新电影剧集信息',
    operationId: 'updateEpisode',
  })
  @LogOperation({
    operateType: OperateType.edit,
    operation: `更新电影剧集信息`,
    name: '更新',
    outside: OperationRecordType.moviesEpisode,
    entity: MoviesEpisodeEntity,
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async updateEpisode(@Body() body: UpdateMoviesEpisodeDto) {
    return this.episodeService.updateEpisode(body);
  }

  /** 获取电影剧集详情 */
  @HttpCode(200)
  @Get('/getEpisodeInfo')
  @ApiResponse({
    status: 200,
    description: '电影剧集详情',
    type: MoviesEpisodeEntity,
  })
  @ApiOperation({
    summary: '获取电影剧集详情',
    operationId: 'getEpisodeInfo',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async getEpisodeInfo(@Query('id') id: number) {
    return this.episodeService.getEpisodeInfo(id);
  }

  /** 删除电影剧集 */
  @HttpCode(200)
  @Post('/deleteEpisode')
  @ApiBody({
    description: '删除电影剧集',
    type: IdDto,
  })
  @ApiOperation({
    summary: '删除电影剧集',
    operationId: 'deleteEpisode',
  })
  @LogOperation({
    operateType: OperateType.delete,
    operation: `删除电影剧集`,
    name: '删除',
    outside: OperationRecordType.moviesEpisode,
    entity: MoviesEpisodeEntity,
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async deleteEpisode(@Body() body: IdDto) {
    return this.episodeService.deleteEpisode(body);
  }
}
